import Axios from "axios";
let http = Axios.create({
  timeout: 10000,
  baseURL: "http://110.40.139.181:8080/admin",
});
export default http;
http.interceptors.request.use(
  (requestConfig) => {
    // console.log('请求前的config:', requestConfig)
    let token = sessionStorage.getItem("token");

    token && (requestConfig.headers["token"] = token);

    return requestConfig;
  },
  (error) => Promise.reject(error)
);

http.interceptors.response.use(
  (res) => {
    // console.log("响应后:", res)

    res.data.token && sessionStorage.setItem("token", res.data.token);

    // loadingInstance.close();

    return res;
  },
  (error) => {
    // let _resp = error.response;

    // switch (_resp) {
    //   case 401:break;
    //   case 500:break;

    // sessionStorage.removeItem("token");
    // return router.push('/login')
    // }
    // return Promise.reject(error.response.data)
    return Promise.reject(error);
  }
);
